package com.example.tests;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;

import com.example.fw.ApplicationManager;
import com.example.tests.TestBase;

public class TestBase {
	
  	static ApplicationManager app;

	
	@BeforeTest
	public void setUp() throws Exception {
		app = new ApplicationManager();
	}


	@AfterTest
	public void tearDown() throws Exception {
		((ApplicationManager) app).stop(); 
	}

	@DataProvider
	public Iterator<Object[]> randomValidGroupGenerator(){
	List<Object[]> list = new ArrayList<Object[]>();
	for (int i = 0; i < 5; i++){
		GroupData group = new GroupData()
		.withName(generateRandomString())
		.withHeader(generateRandomString())
		.withFooter(generateRandomString());
		list.add(new Object[]{group});
	}
	return list.iterator();
	}
	
	public String generateRandomString() {
		Random rnd = new Random();
		
			if (rnd.nextInt(6) == 0){
				return "";
			} else {
				return "test" + rnd.nextInt();
			}	
	}
	
	@DataProvider
	public Iterator<Object[]> randomValidContactGenerator () {
		List<Object[]> list = new ArrayList<Object[]>();
		for (int i = 0; i < 1; i++){
			ContactData contact = new ContactData()
			.withFistName(generateRandomString())
			.withLastName(generateRandomString())
			.withFirstAddress(generateRandomString())
			.withTelHome(generateRandomString())
			.withTelMobile(generateRandomString())
			.withTelWork(generateRandomString())
			.withFistEmail(generateRandomString())
			.withSecondEmail(generateRandomString())
			.withIndexBirthDay(generateRandomIndexBirthDay())
			.withIndexGroup(generateRandomIndexGroup())
			.withIndexBirthMonth(generateRandomIndexBirthMonth())
			.withIndexBirthYear(generateRandomIndexBirthYear())
			.withSecondAddress(generateRandomString())
			.withSecondTelHome(generateRandomString());
			
			list.add(new Object[]{contact});
		}
		
		return list.iterator();
		}
	
	public int generateRandomIndexBirthDay() {
		Random rnd = new Random();
		return rnd.nextInt(30)+1;
	}
	
	public int generateRandomIndexBirthMonth() {
		Random rnd = new Random();
		return rnd.nextInt(12)+1;
	}
	public int generateRandomIndexBirthYear() {
		Random rnd = new Random();
		return rnd.nextInt(2010);
	}
	
	public int generateRandomIndexGroup() {
		Random rnd = new Random();
		return rnd.nextInt(10)+1;
	}
}
